package com.xbao.service.impl;

import com.xbao.dao.RoleMapper;
import com.xbao.model.Role;
import com.xbao.model.RoleRuleRel;
import com.xbao.model.Rule;
import com.xbao.model.UserRole;
import com.xbao.model.req.EmpReq;
import com.xbao.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by qingshengzheng on 18/8/29.
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    //// @Cacheable(cacheManager = "caffeineCacheManager",cacheNames = "getAreaNameByCode", key = "#areaCode")
    public void addRule(Rule rule) {
        roleMapper.addRule(rule);

    }

    @Override
    public void deleteRule(Long id) {
        roleMapper.deleteRUle(id);

    }

    @Override
    public Rule detailRUle(Long id) {
        Rule rule = roleMapper.detailRule(id);
        return rule;
    }


    @Override
    public List<Rule> queryRulesOfUser(Long uid) {
        List<Rule> rules = roleMapper.queryRulesOfUser(uid);
        return rules;
    }

    @Override
    public List<Role> queryRolesOfUser(Long uid) {
        roleMapper.queryRuleOfRole(uid);
        return null;
    }

    @Override
    public void addUserRoles(List<UserRole> userRoles) {
        roleMapper.addUserRoles(userRoles);

    }

    @Override
    public void removeUserRoles(Long uid) {
        roleMapper.removeUserRoles(uid);


    }

    @Override
    public List<Rule> getMyRoles(EmpReq empReq) {
        List<RoleRuleRel> rels = roleMapper.getMyRoles(empReq);
        List<Rule> rules = new ArrayList<Rule>();
        for (RoleRuleRel rel : rels) {
            Rule rule = new Rule();
            rules.add(rule);
        }
        return rules;
    }

    @Override
    public void addRoleRule(RoleRuleRel rel) {
        roleMapper.addRoleRule(rel);

    }

    @Override
    public List<Rule> queryRuleOfRole(Long roleid) {
        return roleMapper.queryRuleOfRole(roleid);
    }

    @Override
    public List<Rule> getMyRoles(Long eid) {
        EmpReq empReq = new EmpReq();
        empReq.setId(eid);
        return getMyRoles(empReq);
    }
}
